package com.example.lsxz;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import okhttp3.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 洛师小助登录
 * @author l9216
 */
public class lsxzlogin {
    public static void main(String[] args) throws IOException {

        Map<String,Object> loginMap=new HashMap<String, Object>();
        //设置账户名和密码
        loginMap.put("username","161164518");
        loginMap.put("password","lynu161164518");

        loginMap.put("code","code");

        //Map转成JSON字符串，因为发起请求是JSON格式。
        JSONObject jsonObject = JSONUtil.parseFromMap(loginMap);
        String content = jsonObject.toString();


        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8,text/plain");
        RequestBody body = RequestBody.create(mediaType, content);
        Request request = new Request.Builder()
                .url("https://apii.lynu.edu.cn/v1/accounts/login/")
                .method("POST", body)
                .addHeader("Host", "apii.lynu.edu.cn")
                .addHeader("Connection", "keep-alive")
                .addHeader("accept", "application/json")
                .addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; OPPO R11 Plus Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 MicroMessenger/7.0.12.1620(0x27000C50) Process/appbrand0 NetType/WIFI Language/zh_CN ABI/arm32")
                .addHeader("charset", "utf-8")
                .addHeader("Accept-Encoding", "gzip,compress,br,deflate")
                .addHeader("content-type", "application/json;charset=utf-8")
                .addHeader("referer", "https://servicewechat.com/wx626b4a9845fb263a/13/page-frame.html")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());

    }
}
